package cn.sumpu.app.coolsk.web.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import cn.sumpu.app.coolsk.domain.OnLineUserListener;
import cn.sumpu.toolkit.common.util.Common;

public class UrlCheck implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String ruri = request.getRequestURI();
		if(!Common.empty(ruri) && ("/buy.htm".equals(ruri)//购买门票
								||"/toprobuy.htm".equals(ruri) 
								||"/probuy.htm".equals(ruri)
								||"/orderView.htm".equals(ruri)//订单查看
								||"/member.htm".equals(ruri)//个人主页
								||"/myTrip.htm".equals(ruri)//我的行程
								||"/memberMain.htm".equals(ruri)//账号主页
								||"/myKeep.htm".equals(ruri)//我的收藏
								||"/myOrder.htm".equals(ruri)//我的订单
								||"/myCmt.htm".equals(ruri)//我的点评
								||"/myPoint.htm".equals(ruri)//我的积分
								
								
								
							)){
			OnLineUserListener onlineUser =  (OnLineUserListener) request.getSession().getAttribute("onlineUser");
			if(onlineUser == null || onlineUser.getMember() == null || Common.empty(onlineUser.getMember().getId())){
				response.sendRedirect("sessionTimeout.htm"); 
				return false;
			}
//		以下为手机url	
		}else if(!Common.empty(ruri) && ("/wapmember.htm".equals(ruri)//我的爽客
				||"/wapmemberdetail.htm".equals(ruri) //爽客个人信息
				||"/wapmyorder.htm".equals(ruri) //我的订单
				||"/wapticketorder.htm".equals(ruri)//订购门票
				||"/wapticketbuy.htm".equals(ruri)//下订单门票
				||"/waproomorder.htm".equals(ruri)//酒店房间订购
				||"/waproombuy.htm".equals(ruri)//下单酒店房间
				||"/wapproductorder.htm".equals(ruri)//线路订购
				||"/wapproductbuy.htm".equals(ruri)//线路下单
			)){
				OnLineUserListener onlineUser =  (OnLineUserListener) request.getSession().getAttribute("onlineUser");
				if(onlineUser == null || onlineUser.getMember() == null || Common.empty(onlineUser.getMember().getId())){
					response.sendRedirect("waptologin.htm"); 
					return false;
				}
			
			}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
	}

}
